package com.bonshotels.PresentationLayer;

import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class FinestraError extends JDialog {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8565904442096263411L;

	private JLabel missatge;
	private JLabel consell;
	private JLabel imatge;
	private JButton surt;
	private boolean tancar;
	
	FinestraError(JFrame parent) {
		super(parent, true);
		getContentPane().setLayout(new GridBagLayout());
		GridBagConstraints constraints = new GridBagConstraints();
		
		String directoriImatges = System.getProperty("user.dir") + 
          File.separator + "imatges" + File.separator;
		ImageIcon imageIcon = new ImageIcon(directoriImatges + "LogoBonsHotels.png");
		imatge = new JLabel("   ");
		imatge.setIcon(imageIcon);
		constraints.gridx = 0;
		constraints.gridy = 0;
		constraints.gridheight = 2;
		constraints.gridwidth = 1;
		constraints.weightx = 0.0;
		constraints.weighty = 0.0;
		constraints.fill = GridBagConstraints.NONE;
		constraints.anchor = GridBagConstraints.CENTER;
		getContentPane().add(imatge, constraints);
		
		missatge = new JLabel();
		constraints.gridx = 1;
		constraints.gridy = 0;
		constraints.gridheight = 1;
		constraints.gridwidth = 1;
		constraints.weightx = 1.0;
		constraints.weighty = 0.0;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.anchor = GridBagConstraints.EAST;
		getContentPane().add(missatge, constraints);	
		
		consell = new JLabel();
		constraints.gridx = 1;
		constraints.gridy = 1;
		constraints.gridheight = 1;
		constraints.gridwidth = 1;
		constraints.weightx = 1.0;
		constraints.weighty = 0.0;
		constraints.fill = GridBagConstraints.HORIZONTAL;
		constraints.anchor = GridBagConstraints.EAST;
		getContentPane().add(consell, constraints);
		
		surt = new JButton("Surt");
		constraints.gridx = 2;
		constraints.gridy = 2;
		constraints.gridheight = 1;
		constraints.gridwidth = 1;
		constraints.weightx = 0.0;
		constraints.weighty = 0.0;
		constraints.fill = GridBagConstraints.NONE;
		constraints.anchor = GridBagConstraints.SOUTHEAST;
		getContentPane().add(surt, constraints);
		surt.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				if(tancar) {
					System.exit(0);
				}
				setVisible(false);
			}
		});
		
		setDefaultCloseOperation(0);
		addWindowListener(new WindowListener() {
			@Override
			public void windowOpened(WindowEvent e) {
			}
			
			@Override
			public void windowIconified(WindowEvent e) {	
			}
			
			@Override
			public void windowDeiconified(WindowEvent e) {
			}
			
			@Override
			public void windowDeactivated(WindowEvent e) {
			}
			
			@Override
			public void windowClosing(WindowEvent e) {
				if(tancar) System.exit(0);	
				dispose();
			}
			
			@Override
			public void windowClosed(WindowEvent e) {
			}
			
			@Override
			public void windowActivated(WindowEvent e) {			
			}
		});
		setResizable(false);
		setSize(new Dimension(500,300));
	}
	
	void setTancar(boolean tancar) {
		this.tancar = tancar;
	}
	
	void setMissatge(String missatge) {
		missatge = "<html><b>" + missatge + "<b></html>";
		this.missatge.setText(missatge);
	}
	
	void setConsell(String consell) {
		consell = "<html><i>" + consell + "<i></html>";
		this.consell.setText(consell);
	}

	
}
